package net.lanelife.casino.cms.web.controller;

import net.lanelife.casino.caipiao.dto.admin.RegistrationCodeDTO;
import net.lanelife.casino.caipiao.dto.admin.RegistrationCodeTable;
import net.lanelife.casino.caipiao.entity.RegistrationCode;
import net.lanelife.casino.caipiao.service.api.IRegistrationCodeService;
import net.lanelife.casino.cms.web.controller.support.CRUDController;
import net.lanelife.casino.common.dto.support.GenericDTO;
import net.lanelife.casino.common.service.support.IGenericService;
import net.lanelife.casino.common.web.resolver.ViewResolver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = RegistrationCodeController.PATH)
public class RegistrationCodeController extends CRUDController<RegistrationCode, Integer, RegistrationCodeDTO, GenericDTO<Integer>, GenericDTO<Integer>, RegistrationCodeTable<RegistrationCodeDTO>> {
	
	public static final String PATH = "/registration-code";
	
	public RegistrationCodeController() {
		super(PATH);
	}

	@Autowired
	private IRegistrationCodeService registrationCodeService;
	
	@Override
	protected IGenericService<RegistrationCode, Integer> getService() {
		return registrationCodeService;
	}
	
	@RequestMapping(value = { "/available:{available}/{id}" }, method = RequestMethod.GET)
	public String available(@PathVariable Integer id, @PathVariable Boolean available) throws Exception {
		registrationCodeService.update(id, available);
		return ViewResolver.getView(PATH + "/list");
	}

}
